package com.yuuzai.openworld.framework.action;

import com.yuuzai.openworld.OpenWorldObject;

public abstract class ActionHandler extends OpenWorldObject {
	
	public boolean init(Action<?> action, ActionContext context) {
		return true;
	}

	public boolean execute(Action<?> action, ActionContext context) {
		return true;
	}

	public boolean onSuccess(Action<?> action, ActionContext context) {
		return true;
	}

	public boolean onFailure(Action<?> action, ActionContext context) {
		return false;
	}

	public boolean run(Action<?> action, ActionContext context) {
		if (this.init(action, context)) {
			if (this.execute(action, context)) {
				return this.onSuccess(action, context);
			} else {
				return this.onFailure(action, context);
			}
		}
		return false;
	}

}
